<?php

class Administration_Model_Mapper_Games extends Jnd_Model_Mapper_Abstract
{
	
    protected $_dict = array(
        'id' => 'idgames', 
        'idTeamHome' => 'idteamhome', 
        'idTeamVisitor' => 'idteamvisitor', 
        'idLocation' => 'idlocation', 
        'date' => 'date', 
        'scoreHomeFirst' => 'scorehomefirst', 
        'scoreHomeSecond' => 'scorehomesecond', 
        'scoreHomeThird' => 'scorehomethird', 
        'scoreHomeOvertime' => 'scorehomeovertime', 
        'scoreHomeShoutout' => 'scorehomeshoutout', 
        'scoreVisitorFirst' => 'scorevisitorfirst', 
        'scoreVisitorSecond' => 'scorevisitorsecond', 
        'scoreVisitorThird' => 'scorevisitorthird', 
        'scoreVisitorOvertime' => 'scorevisitorovertime', 
        'scoreVisitorShoutout' => 'scorevisitorshoutout', 
    	'indexDisplay' => 'indexDisplay',
    	'creationUser' => 'creationuser',
    	'creationDate' => 'creationdate'
    );
    
    protected $_dictDate = array(
        'date' => 'date',
    	'creationDate' => 'creationdate'
    );
    
    
	
    /* (non-PHPdoc)
     * @see Jnd_Model_Mapper_Abstract::recuperationDonneesDepuisModel()
     */
    protected function recuperationDonneesDepuisModel( Jnd_Model_Abstract $objetModel )
    {
		$donnees = parent::recuperationDonneesDepuisModel($objetModel);
		if ( is_null($donnees['pictures']) ) {
			unset($donnees['pictures']);
		}        
		return $donnees;
    }

	/**
     * Methode permettant de générer le Table_Select pour le datagrid
     * @see Jnd_Model_Mapper_Abstract::getListSelect()
     */
    public function getListSelect( $values, $environnement, $identite, $options = null )
    {
        $table = $this->_getTable();
        $tableName = $table->info(Zend_Db_Table_Abstract::NAME);
        $dba = $table->getAdapter();
        $select = $dba->select()->from($tableName, $this->_dict, $table->info(Zend_Db_Table_Abstract::SCHEMA));

        $champ = 'libelleClient';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' LIKE ?', '%' . $values[$champ] . '%');
        }
        $champ = 'prospect';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' = ?', $values[$champ]);
        }
        $champ = 'codeAnael';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' LIKE ?', $values[$champ] . '%');
        }
        $champ = 'statutId';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' = ?', $values[$champ]);
        }
        $champ = 'codePostal';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' = ?', $values[$champ]);
        }
        $champ = 'localite';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' LIKE ?', '%' . $values[$champ] . '%');
        }
        $champ = 'creationUtilisateur';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ' LIKE ?', $values[$champ] . '%');
        }
        $champ = 'creationDate';
        if (isset($values[$champ]) && $values[$champ]) {
            $dt = new Jnd_Date($values[$champ], null, 'fr_FR');
            $select->where('DATE(' . $dba->quoteIdentifier($clientName . '.' . $this->_dict[$champ]) . ') = ?', $dt->getDbDate());
        }
        //      echo $select;
//        die("Select : $select");
        return $select;
    }
}
